<template>
	<view class="information">
		<uni-grid :column="3" :show-border="false" :highlight="true">
			<uni-grid-item v-for="(item, index) in column" :index="index" :key="index"
				v-show="!(item.title=='业务员'&&IsSubAccount)">
				<view class="grid-item-box" @click="toPage(item,item.url)">
					<image :src="item.icon" mode=""></image>
					<text class="text">{{item.title}}</text>
				</view>
			</uni-grid-item>
		</uni-grid>

		<!-- <view @click="printClick" class="" style="position: fixed;bottom: 100rpx;width: 100%;text-align: center;">
			<text style="border-bottom: 1px solid #006FE3;color: #006FE3; padding-bottom: 5rpx;">
				查看打印机购物渠道
			</text>
		</view> -->
	</view>
</template>

<script>
	export default {
		onLoad() {
			this.IsSubAccount = uni.getStorageSync('userInfo').IsSubAccount
		},
		onShow() {
			// 获取票据备注
			this.printKewords = uni.getStorageSync('ReceiptPhrase')
			// 获取催款备注
			this.callForPayKewords = uni.getStorageSync('callForPayRemart')
			this.webviewTitle = uni.getStorageSync('webviewTitle')
			this.userInfo = uni.getStorageSync('userInfo')
			console.log('获取用户信息', this.userInfo)
			this.column.forEach(item => {
				if (item.title == '票据信息') item.url =
					`/pages/user/editUserInfo?type=text&value=${this.printKewords||''}&key=printKewords&title=票据信息`
				else if (item.title == '催款备注') item.url =
					`/pages/user/editUserInfo?value=${this.callForPayKewords||''}&key=callForPayKewords&title=催款备注`
				else if (item.title == '上传微信码' && this.userInfo.WeChatUser) item.icon =
					'/static/information/barCode.png'
				else if (item.title == '上传收款码' && this.userInfo.WeChatPay) item.icon =
					'/static/information/barCode.png'
			})
		},
		data() {
			return {
				// 票据备注
				printKewords: "",
				// 催款备注
				callForPayKewords: "",
				// 公司信息
				CommpayInfo: "",
				// 用户信息
				userInfo: "",
				column: [{
						title: '客户档案',
						icon: '/static/information/customer.png',
						url: '/pages/Information/page/Customer'
					},
					{
						title: '业务员',
						icon: '/static/information/subaccount.png',
						url: '/pages/Information/page/subaccount/subaccount'
					}, {
						title: '商品分类',
						icon: '/static/information/goodsType.png',
						url: '/pages/Information/page/GoodsType/GoodsType'
					}, {
						title: '商品信息',
						icon: '/static/information/goodsInfo.png',
						url: '/pages/Information/page/GoodsInfo/GoodsInfo'
					},
					{
						title: '上传微信码',
						icon: '/static/information/noCode.png',
						url: '/pages/Information/page/ContactPerson/ContactPerson'
					},
					{
						title: '上传收款码',
						icon: '/static/information/noCode.png',
						url: '/pages/Information/page/ContactPerson/ContactPerson'
					},
					{
						title: '票据信息',
						icon: '/static/information/remark.png',
						url: ''
					},
					{
						title: '催款备注',
						icon: '/static/information/remark.png',
						url: ''
					},
					{
						title: '订货码',
						icon: '/static/information/barCode.png',
						url: '/pages/user/ChargeCode'
					},
				],
				IsSubAccount: false
			}
		},
		methods: {
			// 打印机购买渠道
			printClick() {

				uni.navigateTo({
					url: "/pages/user/print"
				})
			},
			toPage(item, url) {
				
				console.log('催款备注', item,url)
				if (item.title === '上传微信码' || item.title === '上传收款码') {
					uni.scanCode({
						scanType: ['qrCode'],
						success: (val) => {
							if (item.title === '上传微信码') {
								this.userInfo.WeChatUser = val.result
								this.column[4].icon = '/static/information/barCode.png'
							} else {
								this.userInfo.WeChatPay = val.result
								this.column[5].icon = '/static/information/barCode.png'
							}
							this.$http('post', '/Base_Manage/Base_User/SaveData', this.userInfo).then(res => {
								if (res.Success) {
									uni.showToast({
										icon: 'none',
										title: '保存成功'
									})
									uni.setStorageSync('userInfo', this.userInfo)
								} else this.$api.msg(res.Msg)
							})
						}
					});
				} else {
					uni.navigateTo({
						url
					})
				}

			}
		}
	}
</script>

<style scoped lang="scss">
	.information {
		height: 100%;
		background-color: #fff;

		.grid-item-box {
			flex: 1;
			// position: relative;
			/* #ifndef APP-NVUE */
			display: flex;
			/* #endif */
			flex-direction: column;
			align-items: center;
			justify-content: center;
			padding: 15px 0;

			image {
				width: 35px;
				height: 35px;
			}

			.text {
				margin-top: 10rpx;
				color: #888;
			}
		}

		&.active {
			background-color: #ccc;
		}
	}
</style>